home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoFileAddSlotted.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "openlog.h"
- #include "trans.h"
- #include "bitmap.h"
- #include "file.h"
- #include "consist.h"
- #include "undo.h"
- #include "io_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "fi_extfuncs.h"
- #include "fi_intfuncs.h"
- #include "log_extfuncs.h"
- #include "undo_extfuncs.h"
- #include "logaction.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
- #include "bf_globals.h"
- #ifdef INIT_LRC_IS_LSN
- # include "log_globals.h"
- #endif
-
-
- void
- undoFileAddSlotted (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- VOLREC *volRec;
- PID *rootPID;
- PID lastPID;
- NODEPAGE *nodePage;
- SLOTTEDPAGE *slottedPage;
- GROUPLINK *nodeLink = NULL;
- GROUPLINK *groupLink = NULL;
- LOGRECORDINFO recordInfo;
- BOOL firstPage;
- FORCEMARK forceMark;
- LSN lsn;
- LRC *rootLRC;
- LRC tempLRC;
-
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
-
- /*
- * get a pointer to the file root page id
- * get flag for whether this is the first page in the file
- */
- rootPID = &(recordHeader->actionPid);
- firstPage = *(BOOL*) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("file root pid:%d", rootPID->page));
-
- if ((volRec = io_FindVolRec(rootPID->volid)) == NULL) {
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * Read in first page of file and grab node type
- */
- if ((nodeLink = bf_ReadPage(UserBufGroup, rootPID, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the node page
- */
- nodePage = (NODEPAGE *) nodeLink->bufFrame;
-
- /*
- * undo the update to the root page
- */
- if (firstPage) {
-
- /*
- * record that the file contains no pages
- */
- nodePage->header.firstLogicalNode = NULLPID;
- nodePage->header.lastLogicalNode = NULLPID;
-
- } else {
-
- /*
- * Get a pointer to the last slotted page in the file
- */
- SM_ASSERT(LEVEL_3, 2*sizeof(SHORTPID) == GET_LOG_IMAGE_SIZE(recordHeader, 1));
- /* get second pid in image 1 */
- lastPID.page = *(((SHORTPID*) GET_LOG_IMAGE(recordHeader, 1))+1);
- lastPID.volid = rootPID->volid;
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("last slotted page:%d", lastPID.page));
-
- /*
- * restore the old lastLogicalNode
- */
- nodePage->header.lastLogicalNode = lastPID.page;
-
- /*
- * read in last page of the file and
- * undo the link update
- */
- if ((groupLink = bf_ReadPage(UserBufGroup, &lastPID, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- groupLink->pageHash->pageType = PAGE_SLOTTED;
-
- /*
- * get a pointer to the node page
- */
- slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
-
- /*
- * Restore the old value of the link
- */
- slottedPage->header.nextLogicalPid = NULLPID;
- }
-
- /*
- * increment the lrc on the page
- */
- rootLRC = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
- INCREMENT_LRC(rootLRC);
-
- /*
- * initialize the log information
- */
- recordInfo.type = LOG_REC_TYPE_COMPENSATION;
- recordInfo.action = LOG_ACTION_FILE_REMOVE_SLOTTED;
- recordInfo.actionPid = rootPID;
- recordInfo.actionLRC = rootLRC;
- recordInfo.imageSize[0] = sizeof(BOOL);
- recordInfo.imageData[0] = (VOID *) &firstPage;
- recordInfo.flags = NOFLAGS;
- recordInfo.nextUndoLSN = recordHeader->previousLSN;
- if (firstPage) {
- recordInfo.imageCount = 1;
- } else {
- tempLRC = slottedPage->header.lrc;
- (void) GENERATE_LRC(&tempLRC);
- recordInfo.imageCount = 3;
- recordInfo.imageSize[1] = sizeof(SHORTPID);
- recordInfo.imageData[1] = (VOID *) &(lastPID.page);
- recordInfo.imageSize[2] = sizeof(LRC);
- recordInfo.imageData[2] = (VOID *) &tempLRC;
- }
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
- &lsn, NOFLAGS)) < 0) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * For the file root page
- * mark the page dependency
- * release the page semaphore
- * release and dirty the page
- */
- DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, rootLRC);
- signalSemaphore( &(nodeLink->pageHash->semaphore) );
- bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
-
-
- /*
- * For the last slotted page
- * mark the page dependency
- * release the page semaphore
- * release and dirty the page
- */
- if (!firstPage) {
- DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, &tempLRC);
- signalSemaphore( &(groupLink->pageHash->semaphore) );
- bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
- }
- }
-